package com.czy.common;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

/**
 * @author czy
 * @date    2019/5/10
 */
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class Result<T> {
    /**
     * 返回数据
     */
    private T   t;

    /**
     * 返回信息
     */
    private String msg;

    /**
     * 返回状态
     */
    private boolean success=true;

    /**
     * 状态码
     */
    private int code;

    /**
     * 请求成功
     * @param object
     * @return
     */
    public static Result success(Object object){
        Result<Object> result = new Result<>(object,"请求成功",true,200);
        return  result;
    }

    /**
     * 自定义请求成功
     * @param object
     * @return
     */
    public static Result success(Object object,String msg){
        Result<Object> result = new Result<>(object,msg,true,200);
        return  result;
    }

    /**
     * 请求失败
     * @return
     */
    public static Result fail(){
        Result<Object> result = new Result<>(null,"请求失败",false,400);
        return result;
    }

    /**
     * 自定义请求失败提示语
     * @param msg
     * @return
     */
    public static Result fail(String msg){
        Result<Object> result = new Result<>(null,msg,false,400);
        return result;
    }

    /**
     * 使用枚举自定义抛出异常
     * @param resultCode
     * @return
     */
//    public static Result fail(ResultCode resultCode){
//        Result<Object> result = new Result<>(null,resultCode.msg(),resultCode.success(),resultCode.code());
//        return result;
//    }

    /**
     * 系统异常
     * @return
     */
    public static Result systemError(){
        return new Result(null,"系统异常",false,501);
    }
}
